package com.project2.controller;


import com.project2.bean.CommonData;
import com.project2.bean.PageBo;
import com.project2.bean.ResultVo;
import com.project2.bean.bo.IssueCreateBO;
import com.project2.bean.po.MarketIssue;
import com.project2.bean.vo.IssueCreateVO;
import com.project2.service.IssueService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @Author: cc
 * @Date: 2022-08-13 17:08
 * @Description: 问题模块
 */
@RestController
@RequestMapping("admin/issue")
public class AdminIssueController {

    @Autowired
    IssueService issueService;


    /**
     * 显示所有问题list
     * @param question
     * @param pageBo
     * @return
     */
    @RequiresPermissions("admin:issue:list")
    @GetMapping("list")
    public ResultVo issueInfo(String question, PageBo pageBo){

        CommonData data  = issueService.issueInfo(question,pageBo);

        return ResultVo.ok(data);
    }

    /**
     * 修改问题
     * @param marketIssue
     * @return
     */
    @RequiresPermissions("admin:issue:update")
    @PostMapping("update")
    public ResultVo issueUpdate(@RequestBody MarketIssue marketIssue){

        MarketIssue issueUpdate =  issueService.issueUpdate(marketIssue);


      return ResultVo.ok(issueUpdate);
    }


    /**
     * 逻辑删除问题
     * @param issueCreateVO
     * @return
     */
    @RequiresPermissions("admin:issue:delete")
    @PostMapping("delete")
    public ResultVo issueDelete(@RequestBody IssueCreateVO issueCreateVO){

     int delete = issueService.issueDelete(issueCreateVO);


        if (delete != 1 ) {
            return ResultVo.wrong("delete error!!");
        }

        return ResultVo.ok();
    }


    /**
     * 新建问题
     * @param issueCreateBO
     * @return
     */

    @RequiresPermissions("admin:issue:create")
    @PostMapping("create")
    public ResultVo issueCreate(@RequestBody IssueCreateBO issueCreateBO){
      IssueCreateVO issueCreate =  issueService.issueCreate(issueCreateBO);

      return ResultVo.ok(issueCreate);
    }
}
